﻿<script type="text/javascript">


    function RevistAddMainGrid() {
        $('#txtFillPerson').textbox('readonly', true);
        $('#txtFillDate').datebox('readonly', true);

        $('#txtFillPerson').textbox('setValue','@ViewData["txtFillPerson"]');

      
        $('#RevisitTaskList').datagrid({
            //width: 'auto',
            //height: 'auto',
            height: 440,
            fitColumns: false, //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            loadMsg: '数据加载中,请稍后……',
            singleSelect:true,
            striped: true,
            pagination: false,//启用分页，默认每页10行
            rownumbers: false,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
            pageSize: 15,//设置 页容量5
            pageList: [10, 15, 20],//设置 页容量下拉框

            columns: [[
           // { field: "taskCode", hidden: true },
            { field: "ID", hidden: true },
             { field: "TaskCode", hidden: true },
            //{ field: "RevisitState", title: "回访状态", width: '3%', align: "center" },
            { field: "RevisitWay", title: "回访方式", width: '5%', align: "center" },
            { field: "Satisfaction", title: "满意度", width: '5%', align: "center" },
            { field: "NotSatisfactionReson", title: "不满意原因", width: '6%', align: "center" },
              
                { field: "StationName", title: "分站", width: '5%', align: "center" },
                { field: "RealAmbulanceSign", title: "车辆", width: '6%', align: "center" },
                { field: "AlarmTel", title: "呼救电话", width: '8%', align: "center" },
                { field: "LinkCall", title: "联系电话", width: '8%', align: "center" },
                { field: "LinkMan", title: "联系人", width: '6%', align: "center" },
                { field: "LocalAddr", title: "现场地址", width: '19%', align: "center" },
                { field: "PatientName", title: "患者姓名", width: '6%', align: "center" },
                { field: "Sex", title: "性别", width: '3%', align: "center" },
                { field: "Age", title: "年龄", width: '3%', align: "center" },
                { field: "AlarmReason", title: "主诉", width: '8%', align: "center" },
                { field: "SendAddr", title: "送往地址", width: '10%', align: "center" },
                { field: "StartTaskTime", title: "生成任务时刻", width: '11%', align: "center", formatter: $.formatTime },
                { field: "DispatcherName", title: "责任调度员", width: '5%', align: "center" },
                { field: "Driver", title: "司机", width: '5%', align: "center" },
                { field: "Doctor", title: "医生", width: '5%', align: "center" },
                { field: "Stretcher", title: "担架员", width: '5%', align: "center" }
            ]],
            toolbar: [
              {

                  id: 'btnDetailDelete',
                  text: '删除已选',
                  iconCls: 'icon-custom-Delete',
                  handler: function () {
                      var selected = $('#RevisitTaskList').datagrid('getSelected');
                      if (selected) {
                      
                          deleteDeliveryDetailJsondate(selected.TaskCode);
                      } else {
                          $.messager.alert('提示', '请选择数据行', 'info', function () {
                          });
                      }
                  }

              }, '-',
               {
                   id: 'btnAdd',
                   text: '添加任务',
                   iconCls: 'icon-add',
                   handler: function () {
                       $('#RevisitAddTask').dialog('open');
                       //$.each(Materials,function(i,info){  //考虑再添加时，将
                       //    $('#PickTaskList').datagrid('checkRow',index)
                       //});
                               //loadData


                       PickTaskGrid();
                       //var rows = $('#PickTaskList').datagrid('getRows');
                       //alert(rows.length);
                       //$.each(rows, function (i, info) {
                       //    alert(i);
                       //    if ($.inArray(rows[i], Materials) >= 0) {
                       //        alert("123");
                       //        $('#PickTaskList').datagrid('deleteRow', i);
                       //    }

                       //});

                   }
               }
            ]

            //,onLoadSuccess: function (data) {
            //    var rows = $('#RevisitTaskList').datagrid('getRows');
            //    $("#total").val(rows);
            //    //setDeliveryViewNumCheck();
            //    // changeDeliveryViewNum();
            //}
        });

        $("#RevisitTaskList").datagrid("loadData", Materials);
     

        var rows = $('#RevisitTaskList').datagrid('getRows'); //获取选中的行
        $("#total").html(rows.length);//选中的行数赋给ID 为total的span标签
      $("#txtFillDate").datebox('setValue',$.GetToday());
    }

    function deleteDeliveryDetailJsondate(ecode) {
        var obj;

        $.each(Materials, function (i, info) {
            if (ecode == info.TaskCode) { obj = info; }

        });

        //for (var i = 0; i < Materials.length; i++) {
        //    if (ecode == Materials[i].TaskCode) {
        //        obj = Materials[i];
        //        break;
        //    }
        //}
        Materials.remove(obj);
   
       
        $("#RevisitTaskList").datagrid("loadData", Materials);
        //$.each(Materials, function (i, info) {
        //    $("#RevisitTaskList").datagrid("refreshRow", i);
        //});
        changeRevisitViewNum();
      //  setDeliveryViewNumCheck();
        var rows = $('#RevisitTaskList').datagrid('getRows'); //获取选中的行
        $("#total").html(rows.length);//选中的行数赋给ID 为total的span标签
       
    }

    //提交了
    function submitRevisitDetailForm() {
        //$('#btnDelivery').linkbutton('disable');
        var jsData = new Array();
        var i = 0;
        var rows = $('#RevisitTaskList').datagrid('getRows');
        $(rows).each(function () {
            var obj = new Object();
            //obj.ID = rows[i].ID;
            obj.TaskCode = rows[i].TaskCode;
            obj.RevisitState = "未回访";

            obj.Station = rows[i].StationName;
            obj.Ambluance = rows[i].RealAmbulanceSign;
            obj.AlarmTel = rows[i].AlarmTel;
            obj.LinkCall = rows[i].LinkCall;
            obj.LinkMan = rows[i].LinkMan;
            obj.LocalAddr = rows[i].LocalAddr;
            obj.PatientName = rows[i].PatientName;
            obj.Sex = rows[i].Sex;
            obj.Age = rows[i].Age;
            obj.AlarmReason = rows[i].AlarmReason;
            obj.SendAddr = rows[i].SendAddr;
            obj.StartTaskTime =$.formatTime(rows[i].StartTaskTime,i);
            obj.DispatcherName = rows[i].DispatcherName;
            obj.Driver = rows[i].Driver;
            obj.Doctor = rows[i].Doctor;
            obj.Stretcher = rows[i].Stretcher;
            obj.FillDate = $("#txtFillDate").datebox("getValue");
            obj.FillPerson = $("#txtFillPerson").datebox("getText");
            
            jsData.push(obj);
            i++;
        });

        $.ajax({
            type: 'POST',
            url: '@Url.Content("~/DD/Revisit/SaveRevisitAdd")',
            data:
                {
                    SubmitTaskDate: $("#txtTaskDate").datebox("getValue"),
                    FillTime: $.GetToday(),
                    EditRowID:EditRowID,
                    sDeliveryDetailInfo: JSON.stringify(jsData)
                },
            dataType: "json",
            success: function (jsData) {
                $.handleJsonResult(jsData, function () {
                    Materials.length = 0;
                    $("#RevistMain").datagrid("reload");
                    $('#RevisitAddMain').dialog("close");
                    $('#RevisitAddTask').dialog("close");
                    EditRowID = "";
                }
                //, function () {
                    //$('#btnDelivery').linkbutton('enable');
                //}
                );
            }
        });
    }
   


</script>

<div id="RevisitAddMain" class="easyui-dialog" title="提交回访任务" data-options="modal:true,collapsible:false,minimizable:false,maximizable:false,closed:true,resizable:true,iconCls:'icon-custom-cDelivery'" style="width: 98%; height: 520px; padding: 0px;">
   
        <div id="tbb" style="padding: 5px; height: auto">
            <table style="width:99%" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td valign="middle" width="8%">填报日期：</td>
                    <td align="left" valign="middle" width="13%">
                        <input class="easyui-datebox" style="width: 110px;" id="txtFillDate">
                    </td>
                    <td align="right" valign="middle" width="8%">填报人：</td>
                    <td align="left" valign="middle" width="13%">
                        <input class="easyui-textbox" style="width: 110px" id="txtFillPerson">
                    </td>
                    <td valign="middle" width="20%">
                        已勾选【
                        <span id="total" style="width:150px; color:red"></span>
                        】回访任务。

                    </td>
                    <td width="12%">
                        &nbsp;&nbsp;
                        <a href="javascript:void(0)" id="btnSumbit" style="width:80px" class="easyui-linkbutton" data-options="iconCls:'icon-save'"  onclick="submitRevisitDetailForm()">提交</a>
                    </td>
                    <td></td>
                </tr>
            </table>

        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="RevisitTaskList" border="0"></table>
        </div>
   
</div>
